package com.itstyle.jpa.web;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.itstyle.jpa.entity.Result;
import com.itstyle.jpa.model.Student;
import com.itstyle.jpa.service.IStudentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "测试接口")
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/test")
public class StudentController {
	private final static Logger LOGGER = LoggerFactory.getLogger(StudentController.class);

	@Autowired
	private IStudentService studentService;

	@ApiOperation(value = "学生List")
	@PostMapping("/list")
	public Result list(HttpServletRequest request) {
		LOGGER.info("学生List");
		List<Object[]> list = studentService.listStudent();
		return Result.ok(list);
	}

	@ApiOperation(value = "学生Map")
	@PostMapping("/listMap")
	public Result listMap(HttpServletRequest request) {
		LOGGER.info("学生Map");
		List<Map<Object, Object>> list = studentService.listStudentMap();
		return Result.ok(list);
	}

	@ApiOperation(value = "学生Model")
	@PostMapping("/listModel")
	public Result listModel(HttpServletRequest request) {
		LOGGER.info("学生Model");
		List<Student> list = studentService.listStudentModel();
		return Result.ok(list);
	}

	@PostMapping("/abc")
	@ResponseBody
	public String abc(@RequestBody Abc abc) {
		return abc.getId() + abc.getName();
	}

	@GetMapping("/date")
	@ResponseBody
	public Abc date(@RequestParam Integer datePeriod) {
		System.out.println("datePeriod:" + datePeriod);
		Abc abc = new Abc();
		abc.setBeginDate(new Date());
		abc.setName("aaa");

//		final  String str =  "/Date(1384171247000+0800)" ;
//	     final  String time = str.substring( 0 ,str.length()- 5 );
//	     System.out.println(time);
//	     
//	     //final String timeZone = str.substring(str.length()-5, str.length());
//	     //System.out.println(timeZone);
//	     final  Date date =  new  Date(Long.parseLong(time));
//	     final  SimpleDateFormat format =  new  SimpleDateFormat( "yyyy-MM-dd" );
//	     System.out.println(format.format(date));

		Date date = new Date();
		Long l = date.getTime();
		System.out.print(l.toString());

		
		return abc;
	}
}
